#include "main.h"

Polygon<val_t> r;
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    // glutInitWindowPosition(770, 400);
    glutCreateWindow(PROGRAM_NAME);
    glutDisplayFunc(&onRenderScene);
    // glutIdleFunc(idle);
    inital();
    glutMainLoop();
    return 0;
}

void onRenderScene(void)
{
    // 使用当前颜色清空缓冲区,即设定背景颜色
    glClear(GL_COLOR_BUFFER_BIT);
    // 设定画笔颜色
    // glColor3f(1, 0, 0);
    glColor3f(0, 1, 1);
    log("%g,%g\n", r.vertices.front().x, r.vertices.front().y);
    r.drawEdge();
    Line<double> line({60, 100}, {250, 290});

    glColor3f(0, 0, 1);
    line.draw();
    glFlush();
    glColor3f(1, 0, 0);
    cohen_sutherlan(r, line);
    glFlush();

    line = Line<double>({60,20 }, {300, 260});
    line.update_edges();
    glColor3f(0, 0, 1);
    line.draw();
    glFlush();
    glColor3f(1, 0, 0);
    LBLineClip(r, line);

    Polygon<val_t> pol;
    pol.addPoint({120,80});
    pol.addPoint({180,80});
    pol.addPoint({150,250});
    // pol.addPoint({180,200});
    // pol.addPoint({140,230});

    // glColor3f(0, 0, 1);
    // pol.drawEdge();
    // glFlush();
    // glColor3f(1, 0, 0);
    // SHLineClip(r, pol);

    glFlush();
}

void inital()
{
    // 定义窗体尺寸
    windowWidth = WINDOW_SIZE;
    windowHeight = WINDOW_SIZE;
    gluOrtho2D(0, windowWidth, 0, windowHeight);

    glClearColor(1, 1, 1, 1);
    // log("111%s\n","");
    r.addPoint({100, 100});
    r.addPoint({200, 100});
    r.addPoint({200, 200});
    r.addPoint({100, 200});
    log("is inside %d\n",r.isPointInside({100, 100})<<1);
    log("is inside %d\n",r.isPointInside({100, 110})<<1);
    log("is inside %d\n",r.isPointInside({100, 50})<<1);



}
void idle(void) //空闲函数
{
    glutPostRedisplay();
}